//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    public class CustomChartsheetView : IOfficeXmlSerializable
    {
        string _guid;
        UInt32 _scale;
        SheetState _state;
        Boolean _zoomToFit;
        PageMargins _pageMargins;
        ChartSheetPageSetup _pageSetup;
        HeaderFooter _headerFooter;
        private const string xmlName = "customSheetView";
        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _guid = c.GetString("guid");
                _scale = c.GetOptionalUInteger("scale", 100);
                _state = c.GetOptionalEnum<SheetState>("_state", SheetState.Visible);
                _zoomToFit = c.GetOptionalBoolean("zoomToFit", false);
                _pageMargins = c.ReadOptionalElement<PageMargins>("pageMargins");
                _pageSetup = c.ReadOptionalElement<ChartSheetPageSetup>("pageSetup");
                _headerFooter = c.ReadOptionalElement<HeaderFooter>("headerFooter");
            }
        }
        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetString("guid", _guid);
                c.SetOptionalUInteger("scale", _scale, 100);
                c.SetOptionalEnum("state", _state, SheetState.Visible);
                c.SetOptionalBoolean("zoomToFit", _zoomToFit, false);
                c.WriteOptionalElement(_pageMargins);
                c.WriteOptionalElement(_pageSetup);
                c.WriteOptionalElement(_headerFooter);
            }
        }
    }
}
